package mid

func MinimumLevels(possible []int) int {
	n := len(possible)
	left, right := 0, 0
	for i := 0; i < n; i++ {
		if possible[i] == 0 {
			right += -1
		} else {
			right += 1
		}
	}
	for i := 0; i < n-1; i++ {
		temp := 0
		if possible[i] == 0 {
			temp += -1
		} else {
			temp += 1
		}
		if left+temp > right-temp {
			return i + 1
		} else {
			left += temp
			right -= temp
		}
	}
	return -1
}
